

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class ServletByParam extends HttpServlet {

	// get方法
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 设置相应内容
		resp.setContentType("text/html;charset=UTF-8");

		PrintWriter out = resp.getWriter();
		String title = "使用GET方法读取表单数据";
		String name = req.getParameter("name");

		//String name = new String(nameParam.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
		String docType = "<!DOCTYPE html> \n";
		out.println(docType +
				"<html>\n" +
				"<head><title>" + title + "</title></head>\n" +
				"<body bgcolor=\"#f0f0f0\">\n" +
				"<h1 align=\"center\">" + title + "</h1>\n" +
				"<ul>\n" +
				"  <li><b>站点名</b>："
				+ name + "\n" +
				"  <li><b>网址</b>："
				+ req.getParameter("url") + "\n" +
				"</ul>\n" +
				"</body></html>");
		//super.doGet(req, resp);
	}

	//post方法
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//机智，使用doGet方法
		doGet(req,resp);
	}

	// delete方法
	@Override
	protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		super.doDelete(req, resp);
	}

	/**
	 * 销毁
	 */
	@Override
	public void destroy() {
		super.destroy();
	}
}
